const express = require('express')
const app=express();
const AboutModel = require('../AboutSchema')

const router =express.Router()
//http://localhost:3000/mongo/add
router.post('/add',(req, res) => {
    console.log(req);
    let clazz =new  AboutModel(req.body)
    clazz.save(function (err,result){
        if(err){
            res.json({
                code:1001,
                msg:'插入数据失败'
            })
        }else{
            res.json({
                code:1002,
                msg:'插入数据成功',
                data:result
            })
        }
    })
})
// 查找
router.get('/find',(req, res) => {
  if(req.query){
    delete req.query.page
    delete req.query.limit
  }
  AboutModel.find(req.query,function (err,result){
      if(err){
          res.json({
              code:1001,
              msg:'查找数据失败'
          })
      }else{
          res.json({
              code:200,
              msg:'查找数据成功',
              data:result
          })
      }
  })
})
module.exports=router;
